import { UserProfilesAPI } from "@/request/api.js"
export default {
    namespaced: true,
    state: {
        userInfo: {
            //用户昵称
            nickName: '',
            //用户鸡腿数
            coin: '',
            //用户头像
            headImg: require('../../assets/img/userImg.f8bbec5e.png'),
        },
        cartTotal: '0',
    },
    mutations: {
        //修改登录模态框状态
        changeUserInfo(state, payload) {
            if (payload.userInfo.nickName == "何超") {
                payload.userInfo.coin = 1000
            }
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        initUserInfo(state) {
            state.userInfo = {
                //用户昵称
                nickName: '',
                //用户鸡腿数
                coin: '',
                //用户头像
                headImg: require('../../assets/img/userImg.f8bbec5e.png'),


            };
            state.cartTotal = 0;
        }
    },
    actions: {
        async asyncUserInfo(context) {
            let user = await UserProfilesAPI();
            console.log("user", user.data);
            context.commit("changeUserInfo", user.data);
        }
    }
}